<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>区域管理编辑</title>
	<!-- import css and js --> 
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
<script type="text/javascript">
var basic_Url="${ctx}/yd/basic/measurementUnit";
$(function(){
$("#inputForm").validate({			   
	onsubmit: true,
	 /*执行ajaxsubmit  */ 
    submitHandler: function(editform) {
            
        //alert(jsonInfo); 
        try{			    		
            url =  basic_Url+"/save.do";
            var api = frameElement.api;
        	var W = api.opener;
            getReturnMessage(url,"inputForm",W.searchAP);
            W.mid=$("#materialsidadd").val();
        }catch(e){alert(e)}
    }
 }
);

 
 
 
})
function submitForm(param){
	var bool=true;
	var zs =/^[0-9]{0}([0-9]|[.])+$/;
	if($("#unitconvert").val() == ""){
		$("#span1").text("不能为空");
		bool=false;
	}else if(!zs.test($("#unitconvert").val())){
		$("#span1").text("只能输入数字");
		bool=false;
	}
    //设置ajax全局同步
    if(bool){
    	jQuery.ajaxSettings.async = false;
      	$("#submitFlag").val(param);
        $("#inputForm").submit();
    }
 }		
function yzzs(){
	var zs = /^[0-9]{0}([0-9]|[.])+$/;
	var unitconvert =document.getElementById("unitconvert");
	if(unitconvert.value != null && unitconvert.value.length > 0){
		if(!zs.test(unitconvert.value)){
			if(document.getElementById("span1") == null){
				$("#unitconvert").after("<span id='span1' style='color: red'>只能输入数字</span>");
				return false;
			}
		}else{
			if(document.getElementById("span1") != null){
				$("#span1").remove();
			}
			
		}
	}	
}
function hideUnitconvert(val){
	if(val == 0){
		$("#unitconvert").val("1");
		$("#unitconvert").attr("readonly","readonly");
	}else if(val == 1){
		$("#unitconvert").val("");
		$("#unitconvert").removeAttr("readonly");
	}
}
</script>

</head>

<body>

<form id="inputForm" action="" method="post">
<input type="hidden" id="id" name="id" value="${bmu.id}"/>
<!-- 用于标识提交按钮 -->
<input type="hidden" id="submitFlag" value="" />
 <div class="pageContent" >
    <div class="panel">
         <table class="TableBlock" align="center">
                   <tr>
                    <td nowrap>单位名称:</td>
   		                 <td>
   		                 <select id="unitname" name="unitname">
   		                 	<option></option>
   		                 	<c:forEach items="${bfu}" var="bfu">
   		                 		<option id="${bfu.unitcode }" value="${bfu.unitname }">${bfu.unitname }</option>
   		                 	</c:forEach>
   		                 </select>
						<script type="text/javascript">
						$("#unitname").change(function(){
							$("#unitcode").val($("#unitname").find("option:selected").attr("id"));
						});
							$("#unitname").val('${bmu.unitname}');
						</script>
<%--    		                 	<input type="text" id="unitname" name="unitname" class="required"   value="${bmu.unitname}" /> --%>
   		                 	<c:choose>
   		                 		<c:when test="${empty bmu.materialsid}">
   		                 			<input type="hidden" id="materialsidadd" name="materialsidadd" value="${mid}" />
		   		                 	<input type="hidden" id="materialsnameadd" name="materialsnameadd" value="${mname}" />
		   		                 	<input type="hidden" id="materialscodeadd" name="materialscodeadd" value="${mcode}" />
   		                 		</c:when>
   		                 		<c:otherwise>
   		                 			<input type="hidden" id="materialsidadd" name="materialsidadd" value="${bmu.materialsid}" />
		   		                 	<input type="hidden" id="materialsnameadd" name="materialsnameadd" value="${bmu.materialscode}" />
		   		                 	<input type="hidden" id="materialscodeadd" name="materialscodeadd" value="${bmu.materialsname}" />
   		                 		</c:otherwise>
   		                 	</c:choose>
   		                 </td>
   		           </tr>
   		           <tr>
                    <td nowrap>单位编码:</td>
   		                 <td>
   		                	<input type="text" id="unitcode" name="unitcode" class="required" value="${bmu.unitcode}"  readonly="readonly"/>
   		                 </td>
   		           </tr>
   		            <tr>
   		                 <td nowrap>换算率:</td>
   		                  <td>
	                  		<input type="text" id="unitconvert" name="unitconvert"  class="required" value="${bmu.unitconvert}" onkeyup="yzzs()"/>
   		                 	<span id='span1' style='color: red'></span>
   		                 </td>
   		                </tr>
   		            <c:if test="${count le 0 }">
  		              <tr>
   		              <td>是否为默认单位:</td>
   		             <td colspan="3">
   		             <select id="defaultUnit" name="defaultUnit" class="required" style="width: 50px;" onchange="hideUnitconvert(this.value)">
   		                 	<option></option>
   		                 	<option id="0" value='0'>是</option>
   		                 	<option id="1" value='1'>否</option>
   		             </select>
   		             <script type="text/javascript">
   		               $("#defaultUnit").val('${bmu.defaultUnit}');
   		             </script>
   		             </td>
   		           </tr>
   		           </c:if>
   		           <c:if test="${flag == 'edit'}">
   		           	<tr>
   		              <td>是否为基本单位:</td>
   		             <td colspan="3">
   		             <c:choose>
   		             	<c:when test="${bmu.defaultUnit == 0}">
   		             		<input type="text" id="defaultUnit" name="defaultUnit" readonly="readonly" class="required" value="是"/>
   		             	</c:when>
   		             	<c:otherwise>
   		             		<input type="text" id="defaultUnit" name="defaultUnit" readonly="readonly" class="required" value="否"/>
   		             	</c:otherwise>
   		             </c:choose>
   		             </td>
   		           </tr>
   		           </c:if>
   		           <tr>
   		           	<td>备注:</td>
   		           	<td colspan="3"><input id="remark" name="remark" value="${bmu.remark}" /></td>
   		           </tr>
                </table>               
         </div>
         <div class="formBar">
	        <ul>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save" onclick="submitForm(1)">保存</button></div></div></li>
		       <li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="CloseDialog()">关闭</button></div></div></li>
	        </ul>
        </div>    
    </div>
</form>
</body>
</html>
